using System;
using System.Globalization;
using UnityEngine;

namespace WXB
{
	public class PropertyHelper
	{
		public static float	stringToFloat(string str)
		{
			float value = 0;
			if (float.TryParse(str, out value) == false)
				return 0;

			return value;
		}
		
        public static UnityEngine.Color CreateARGB(uint argb)
        {
            UnityEngine.Color color = new UnityEngine.Color();
            color.b = (argb & 0xFF) / 255.0f;
            argb >>= 8;

            color.g = (argb & 0xFF) / 255.0f;
            argb >>= 8;

            color.r = (argb & 0xFF) / 255.0f;

            argb >>= 8;
            color.r = (argb & 0xFF) / 255.0f;

            return color;
        }

        public static uint CalculateARGB(UnityEngine.Color color)
        {
            return (uint)(color.a * 255) << 24 | (uint)(color.r * 255) << 16 | (uint)(color.g * 255) << 8 | (uint)(color.b * 255);
        }

		public static UnityEngine.Color stringToColour(string str)
		{
            return CreateARGB(uint.Parse(str, NumberStyles.HexNumber));
		}

		public static string colourToString(UnityEngine.Color val)
		{
            return string.Format("{0:x}", CalculateARGB(val));
		}
	};
}
